//
//  LBViewController.m
//  LBHorizontalLoopView
//
//  Created by liuboliu on 08/29/2021.
//  Copyright (c) 2021 liuboliu. All rights reserved.
//

#import "LBViewController.h"
#import <LBHorizontalLoopView/LBHorizontalLoopView.h>
#import "LBCell.h"
#import "LBBannerCell.h"

@interface LBViewController () <LBHorizontalLoopViewDelegate, LBHorizontalLoopViewDataSource>

@property (nonatomic, strong) LBHorizontalLoopView *loopView;

@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation LBViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:self.loopView];
    NSMutableArray *array = [NSMutableArray array];
    for (int i = 0; i < 10; i ++) {
        NSString *content = [NSString stringWithFormat:@"%d",i];
        [array addObject:content];
    }
    self.dataArray = array.copy;
    [self.loopView reloadDataAndStartRoll];
	// Do any additional setup after loading the view, typically from a nib.
}

#pragma mark - LBHorizontalLoopViewDelegate, LBHorizontalLoopViewDataSource
- (NSInteger)viewNumberOfLoopView:(LBHorizontalLoopView *)loopView
{
    return self.dataArray.count;
}

- (LBHorizontalLoopViewCell *)cellForIndex:(NSInteger)index inLoopView:(LBHorizontalLoopView *)loopView
{
    if (index % 2 == 0) {
        LBCell *cell = [loopView dequeueReusableCellWithIdentifier:NSStringFromClass([LBCell class])];
        NSString  *content = self.dataArray[index];
        [cell updateWithModel:content];
        return cell;
    }
    LBBannerCell *cell = [loopView dequeueReusableCellWithIdentifier:NSStringFromClass([LBBannerCell class])];
    return cell;
}

- (void)loopView:(LBHorizontalLoopView *)loopView didClickCellAtIndex:(NSInteger)index
{
}

- (void)loopView:(LBHorizontalLoopView *)loopView didScroll:(UIScrollView *)scrollView
{
    
}

- (void)loopView:(LBHorizontalLoopView *)loopView didScrollToCellAtIndex:(NSInteger)index
{
    
}

#pragma mark - lazy load
- (LBHorizontalLoopView *)loopView
{
    if (!_loopView) {
        _loopView = [[LBHorizontalLoopView alloc] initWithFrame:CGRectMake(0, 100, CGRectGetWidth(self.view.bounds), 150)];
        [_loopView registerClass:[LBCell class] forViewReuseIdentifier:NSStringFromClass([LBCell class])];
        [_loopView registerClass:[LBBannerCell class] forViewReuseIdentifier:NSStringFromClass([LBBannerCell class])];
        _loopView.restartTimeEndingDragging = NO;
        _loopView.style = LBHorizontalLoopViewStyleAlphaChange;
        _loopView.dataSource = self;
        _loopView.delegate = self;
    }
    return _loopView;
}

@end
